package com.z1.core.http;

import com.z1.core.exception.Z1Exception;

public class UrlFormat {

	public static final String transfromUrl(String url) {
		if (null == url || url.trim().equals("")) {
			throw new Z1Exception("request url is null."); 
		}
		return url += (-1 == url.indexOf("?")) ? 
			("?ts=" + System.currentTimeMillis()) : 
			("&&ts=" + System.currentTimeMillis());
	}
	
	public static final String trimUrl(String url) {
		if (null == url || url.trim().equals("")) {
			throw new Z1Exception("request url is null."); 
		}
		String[] urlParts = url.split("\\?");
		StringBuffer buffer = new StringBuffer();
		String temp = urlParts[0].replaceAll("\\\\\\\\", "/");
		temp = temp.replaceAll("/+", "/");
		buffer.append(temp);
		for (int i = 0; i < urlParts.length; i++) {
			buffer.append("?").append(urlParts[i]);
		}
		return buffer.toString();
	}

}
